package com.future.lock.mall.entity.response;

import com.future.lock.common.http.response.HttpResponse;
import com.future.lock.me.order.utils.JSONUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by yzh on 2017/9/20.
 */
public class BaseDataResponse<T> extends HttpResponse {

    public T data;

    private final Class<T> clz;

    public BaseDataResponse(Class<T> clz) {
        this.clz = clz;
    }

    @Override
    protected void parseData(String dataString) throws JSONException {
        try {
            data = JSONUtil.parseJSONObject(new JSONObject(dataString), clz);
        }
        catch (Exception e) {
            e.printStackTrace();
            data = null;
            throw new JSONException(e.getMessage());
        }

    }
}
